package com.oldbook.manage.controller;

import com.oldbook.common.annotation.Log;
import com.oldbook.common.core.controller.BaseController;
import com.oldbook.common.core.domain.AjaxResult;
import com.oldbook.common.core.page.TableDataInfo;
import com.oldbook.common.enums.BusinessType;
import com.oldbook.manage.domain.vo.TextbookVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.oldbook.manage.domain.Textbook;
import com.oldbook.manage.service.ITextbookService;

/**
 * 教材管理Controller
 *
 * @author Exiaoke
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/manage/textbook")
@Api(tags = "教材管理管理")
public class TextbookController extends BaseController {

    @Autowired
    private ITextbookService textbookService;

    /**
     * 查询教材管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:list')")
    @GetMapping("/list")
    @ApiOperation("查询教材管理列表")
    public TableDataInfo list(@ApiParam("教材管理对象") Textbook textbook) {
        startPage();
        List<TextbookVO> list = textbookService.selectTextbookList(textbook);
        return getDataTable(list);
    }

//    /**
//     * 导出教材管理列表
//     */
//    @PreAuthorize("@ss.hasPermi('manage:textbook:export')")
//    @Log(title = "教材管理", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ApiOperation("导出教材管理列表")
//    public void export(HttpServletResponse response, @ApiParam("教材管理对象") Textbook textbook) {
//        List<TextbookVo> list = textbookService.selectTextbookList(textbook);
//        ExcelUtil<Textbook> util = new ExcelUtil<Textbook>(Textbook.class);
//        util.exportExcel(response, list, "教材管理数据");
//    }

    /**
     * 获取教材管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:query')")
    @GetMapping(value = "/{textbookId}")
    @ApiOperation("获取教材管理详细信息")
    public AjaxResult getInfo(@PathVariable("textbookId") @ApiParam("textbookId的值") Long textbookId) {
        return success(textbookService.selectTextbookByTextbookId(textbookId));
    }

    /**
     * 新增教材管理
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:add')")
    @Log(title = "教材管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增教材管理")
    public AjaxResult add(@RequestBody @ApiParam("要添加的教材管理对象") Textbook textbook) {
        return toAjax(textbookService.insertTextbook(textbook));
    }

    /**
     * 修改教材管理
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:edit')")
    @Log(title = "教材管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改教材管理")
    public AjaxResult edit(@RequestBody @ApiParam("要修改的教材管理对象") Textbook textbook) {
        return toAjax(textbookService.updateTextbook(textbook));
    }

    /**
     * 删除教材管理
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:remove')")
    @Log(title = "教材管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{textbookIds}")
    @ApiOperation("删除教材管理")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的textbookId数组") Long[] textbookIds) {
        return toAjax(textbookService.deleteTextbookByTextbookIds(textbookIds));
    }

//    /**
//     * 添加购物车
//     */
//    @PreAuthorize("@ss.hasPermi('manage:category:add')")
//    @Log(title = "添加购物车", businessType = BusinessType.INSERT)
//    @PostMapping("/addCart")
//    @ApiOperation("添加购物车")
//    public AjaxResult addCart(@RequestBody @ApiParam("要添加的购物车对象") Cart cart) {
//        return toAjax(cartService.insertCart(cart));
//    }
}